package com.kly.user.db.dao;
import com.fqgj.common.base.BaseMapper;
import com.kly.user.db.dbo.UserConversationDBO;
import com.kly.user.db.entity.UserConversationEntity;
import com.kly.user.dto.chatter.request.ConversationOPReq;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
* User: linqu
* Date: 2023-06-08
* Time: 19:27:43.185
*/

public interface UserConversationDao  extends BaseMapper<UserConversationEntity> {

    List<UserConversationEntity> queryConversationByTarget(ConversationOPReq req);

    UserConversationEntity queryConversation(ConversationOPReq req);

    UserConversationEntity saveOrUpdate(UserConversationEntity record);

    Integer doAction(String userCode, String userCodeFriend, Integer op, String reason);

    Integer updateLeaveTime(Map<String,Object> map);

    Integer updateEnterAndLeaveTime(Map<String,Object> map);


    List<UserConversationEntity> queryConversationByTargetIdAndUserCode(Map<String,Object> map);

    List<UserConversationEntity> queryConversionByUserCode(Map<String, Object> map);

    List<UserConversationEntity> queryConversionByUserCode(String userCode, String userCodeFriend, Integer conversationType);

    int deleteById(Long id);

    int removeChat(String userCode, String userCodeFriend);

    /**
     * 删除会话记录
     * @param userCode
     * @param userCodeFriend
     * @return
     */
    int doDeleted(String userCode, String userCodeFriend);

    List<UserConversationDBO> queryAllConversionByUserCode(String userCode);

    List<UserConversationDBO> queryOnlineUsers(String userCode);

    List<UserConversationDBO> queryOnlineModels(String userCode);

    UserConversationEntity queryConversionByUserCode(String userCode, String userCodeFriend);

    /**
     * 读取会话中对方top的userCode
     * @param userCode
     * @return
     */
    List<String> queryUserCodeFriend(String userCode);

    int countByGroupId(String modelUserCode, Date beginOfDate);

    int countByGroupId2(String modelUserCode, Date beginOfDate);

    /**
     * 查询model当天会话数
     * @param modelUserCode
     * @return
     */
    int getDayConversationCount(String modelUserCode, Date nowDate);

    /**
     * 读取用户的会话信息
     * @param userCode
     * @return
     */
     int getUserDayConversationCount(String userCode);


    /**
     * 判断是否有已建联
     * @param chatterUserCode
     * @param userCode
     * @return
     */
    int haveChatterConversation(String chatterUserCode, String userCode);

    int haveConversation(String chatterUserCode, String userCode);


    /**
     * model是否发送过消息给user
     * @param chatterUserCode
     * @param modelUserCode
     * @param userCode
     * @return
     */
    UserConversationEntity conversationByModel(String chatterUserCode, String modelUserCode, String userCode);

    /**
     * 当天建联数
     * @param userCode
     * @return
     */
    int getUserTodayConversationCount(String userCode);

    /**
     * 读取用户最近时间内聊天人数
     * @param userCode
     * @param latestTime
     * @return
     */
    int getUserLastConversationCount(String userCode, Date latestTime);

    /**
     * 小于时间的会话
     * @param latestTime
     * @return
     */
     List<UserConversationEntity> getUserLastConversationList(Date latestTime);


    /**
     * 读取用户小于时间的会话
     * @param userCode
     * @param latestTime
     * @return
     */
    List<UserConversationEntity> getConversationByUserCode(String userCode, Date latestTime);

    /**
     * 更新最近一条消息
     */
    Integer updateLastMsg(String fromUserId, String toUserId, String content);
}